package view;
/**
* Beschreibung
* Das Hauptfenster des Programms
* @version 1 vom 09.12.2013
* @author Jonas, Alex
*/

import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;

import controller.DatenController;
import controller.IController;
import model.Mitarbeiter;

@SuppressWarnings("serial")
public class MainWin extends JFrame {

	
	public static void main(String[] args) {
		new MainWin().setVisible(true);
	}
	FrameEvents events = new FrameEvents(this);
	Rectangle conBounds;
	private JPasswordField psfLog;
	private JTextField txfLog;

	/**
	 * Create the frame.
	 */
	private JPanel panelBorder;
	public JPanel getBorder()
	{
		return panelBorder;
	}
	
	public MainWin() {
		
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {}
		getContentPane().addMouseListener(events);
		getContentPane().addMouseMotionListener(events);
		addWindowFocusListener(events);

		setUndecorated(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 789, 594);
		getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
		
		panelBorder = new JPanel();
		panelBorder.setBackground(Color.WHITE);
		panelBorder.setBorder(new LineBorder(new Color(255, 0, 0)));
		getContentPane().add(panelBorder);
		panelBorder.setLayout(null);
		
		ImageBox ImgLogo = new ImageBox();
		ImgLogo.setBounds(10, 1, 113, 35);
		panelBorder.add(ImgLogo);
		ImgLogo.setIcon(new ImageIcon(MainWin.class.getResource("/Bilder/Logo_kurz.jpg")));
		JTabbedPane tabbedPaneMain = new JTabbedPane(JTabbedPane.TOP);
		tabbedPaneMain.setBounds(10, 34, 769, 549);
		panelBorder.add(tabbedPaneMain);
		
		final JPanel pnlMitar = new JPanel();
		tabbedPaneMain.addTab("Ger\u00E4teverwaltung", null, pnlMitar, null);
		pnlMitar.setLayout(null);
		
		JPanel pnlMitarTabs = new JPanel();
		pnlMitarTabs.setBounds(0, 0, 785, 81);
		pnlMitar.add(pnlMitarTabs);
		pnlMitarTabs.setLayout(null);
		
		JButton btneinweisungsuebersichtgeraet = new JButton("<HTML><BODY><div align=\"center\">Einweisungs\u00FCbersicht<br>Ger\u00E4t</BODY></HTML>");
		btneinweisungsuebersichtgeraet.setBackground(Color.WHITE);
		btneinweisungsuebersichtgeraet.setBounds(10, 11, 137, 59);
		pnlMitarTabs.add(btneinweisungsuebersichtgeraet);
		
		JButton btneinweisungsuebersichtperson = new JButton("<HTML><BODY><div align=\"center\">Einweisungs\u00FCbersicht<br>Person</BODY></HTML>");
		btneinweisungsuebersichtperson.setBackground(Color.WHITE);
		btneinweisungsuebersichtperson.setBounds(157, 11, 137, 59);
		pnlMitarTabs.add(btneinweisungsuebersichtperson);
		btneinweisungsuebersichtperson.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			 JPanel pnlEinweisungPerson = new pnlEinweisungPerson();
		      pnlEinweisungPerson.setBounds(0, 80, 764, 444);
		      pnlMitar.add(pnlEinweisungPerson);
		      pnlEinweisungPerson.setVisible(true);
		      pnlMitar.repaint();
			}
		});
		
		psfLog = new JPasswordField();
		psfLog.setBounds(666, 31, 86, 20);
		pnlMitarTabs.add(psfLog);
		
		txfLog = new JTextField();
		txfLog.setBounds(666, 11, 86, 20);
		pnlMitarTabs.add(txfLog);
		txfLog.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("Username:");
		lblNewLabel.setBounds(611, 11, 55, 14);
		pnlMitarTabs.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Passwort:");
		lblNewLabel_1.setBounds(611, 31, 51, 17);
		pnlMitarTabs.add(lblNewLabel_1);
		
		final JButton btnErfGer = new JButton("<HTML><BODY><div align=\"center\">Ger\u00E4te<br>erfassen</BODY></HTML>");
		btnErfGer.setBackground(Color.WHITE);
		btnErfGer.setBounds(304, 11, 85, 59);
		pnlMitarTabs.add(btnErfGer);
		btnErfGer.setVisible(false);
		
		final JButton btnErfEin = new JButton("<HTML><BODY><div align=\"center\">Einweisung<br>erfassen</BODY></HTML>");
		btnErfEin.setBackground(Color.WHITE);
		btnErfEin.setBounds(304, 11, 85, 59);
		pnlMitarTabs.add(btnErfEin);
		btnErfEin.setVisible(false);
		
		final JButton btnErfPer = new JButton("<HTML><BODY><div align=\"center\">Personal<br>erfassen</BODY></HTML>");
		btnErfPer.setBackground(Color.WHITE);
		btnErfPer.setBounds(399, 11, 85, 59);
		pnlMitarTabs.add(btnErfPer);
		btnErfPer.setVisible(false);
		
		final JButton btnDruck = new JButton("Drucken");
		btnDruck.setBackground(Color.WHITE);
		btnDruck.setBounds(494, 11, 91, 29);
		pnlMitarTabs.add(btnDruck);
		btnDruck.setVisible(false);
		
		final JButton btnExport = new JButton("Exportieren");
		btnExport.setBackground(Color.WHITE);
		btnExport.setBounds(494, 41, 91, 29);
		pnlMitarTabs.add(btnExport);
		btnExport.setVisible(false);
		
		JButton btnLog = new JButton("Login");
		btnLog.setBounds(666, 58, 91, 23);
		pnlMitarTabs.add(btnLog);
		
		JLabel lblOszimtGerteeinweisung = new JLabel("OSZIMT - Ger\u00E4teverwaltung");
		lblOszimtGerteeinweisung.setBounds(368, 9, 143, 14);
		panelBorder.add(lblOszimtGerteeinweisung);
		
		JButton btnExit = new JButton("X");
		btnExit.setBounds(726, 1, 53, 23);
		panelBorder.add(btnExit);
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		
		btnLog.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				IController defcon = new DatenController();
				if(defcon.checkPassword(txfLog.getText(), new String(psfLog.getPassword()))){
					System.out.println("Logged");	
						Mitarbeiter m = defcon.getMitarbeiter(txfLog.getText());
						if(m.getClass().getName().equals("model.Stationsbevollmaechtigter")){
							btnErfEin.setVisible(true);
							btnErfPer.setVisible(true);
							btnDruck.setVisible(true);
							btnExport.setVisible(true);	
							btnErfGer.setVisible(false);
						}else if(m.getClass().getName().equals("model.Medizintechniker")){
							btnErfGer.setVisible(true);
							btnErfEin.setVisible(false);
							btnErfPer.setVisible(false);
							btnDruck.setVisible(false);
							btnExport.setVisible(false);	
						}
				}else{
					System.out.println("Login Failed");
				}				
			}
		});
		conBounds = tabbedPaneMain.getBounds();
	}


}
